from collections import Counter

dic_pok = {'2':1,'3':2,'4':3,'5':4,'6':5,'7':6,'8':7,'9':8,'T':9,'J':10,'Q':11,'K':12,'A':13}
all_pok_values = '23456789TJQKA'
def jugPokerType(player1_poker_value,player1_poker_suit):
    play1_type = 1
    #判断是否是同种花色
    if len(Counter(player1_poker_suit))>1:#不是同一花色
        dict_play1_value = Counter(player1_poker_value)
        #判断是否有相同的值出现
        len_play_value = len(dict_play1_value)
        if len(dict_play1_value)!=5:
            #有相同的值出现
            max_value_count = max(dict_play1_value.items(),key=lambda x:x[1])
            if len_play_value==4:
                play1_type = 2
            elif len_play_value==3:
                #可能是2+2+1,也可能是3+1+1
                if max_value_count[1]==3:
                    play1_type = 4
                else:
                    play1_type = 3
            else:
                #可能是4+1，也可能是3+2
                if max_value_count[1]==4:
                    play1_type = 8
                else:
                    play1_type = 7
        else:
            #没有相同值出现
            str_tem = "".join(player1_poker_value)
            if str_tem in all_pok_values:
                play1_type = 5
    else:
        #花色相同，有可能只是花色相同，也有可能是同花顺
        #花色相同，不可能有相同的牌面
        str_tem = "".join(player1_poker_value)
        if str_tem in all_pok_values:
            if str_tem==all_pok_values[-5:]:
                play1_type = 10
            else:
                play1_type = 9
        else:
            play1_type = 6
    return play1_type

def pokerCompare(x):
    '''比较两种手牌的大小'''
    player1 = x[:5]
    player2 = x[5:]
    player1.sort(key=lambda x: (dic_pok[x[0]], x[1]))
    player2.sort(key=lambda x: (dic_pok[x[0]], x[1]))

    player1_poker_value = [i[0] for i in player1]
    player2_poker_value = [i[0] for i in player2]
    player1_poker_suit = [i[1] for i in player1]
    player2_poker_suit = [i[1] for i in player2]

    player1_type = jugPokerType(player1_poker_value, player1_poker_suit)
    player2_type = jugPokerType(player2_poker_value, player2_poker_suit)

    if player1_type > player2_type:
        return 1
        # 如果不相同意味着牌面类型即可比较大小dd
    elif player2_type > player1_type:
        return 0
    else:
        # 牌面类型一致 那么就要详细比较牌面值得大小了
        dict_play1_value = Counter(player1_poker_value)
        dict_play2_value = Counter(player2_poker_value)
        sort_play1_value_count = sorted(dict_play1_value.items(), key=lambda x: (x[1], dic_pok[x[0]]), reverse=True)
        sort_play2_value_count = sorted(dict_play2_value.items(), key=lambda x: (x[1], dic_pok[x[0]]), reverse=True)
        for i in range(len(sort_play1_value_count)):
            if dic_pok[sort_play1_value_count[i][0]] == dic_pok[sort_play2_value_count[i][0]]:
                continue
            else:
                return 1 if dic_pok[sort_play1_value_count[i][0]] > dic_pok[sort_play2_value_count[i][0]] else 0

result = 0
with open('p054_poker.txt') as f:
    for i in f:
        tmp = i.replace('\n','')
        tmps = tmp.split(' ')
        result += pokerCompare(tmps)
print(result)